/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model.Dto;

import Common.Constants;
/**
 *
 * @author Quang Nhat
 */
public class UserAccount {
    private String username;
    private String role;
    private String fullname;
    private boolean active;

    private void Initial(String username, String role, String fullname, boolean active) {
        this.username = username;
        this.role = role;
        this.fullname = fullname;
        this.active = active;
    }

    public UserAccount(String username, String role, String fullname, boolean active) {
        Initial(username, role, fullname, active);
    }
    
    public UserAccount(String username, boolean isAdmin, boolean isAccountant, String fullname, boolean active) {
        StringBuilder r = new StringBuilder("^");
        if (isAdmin) {
            r.append(Constants.ROLE_ADMIN).append("^");
        }
        if (isAccountant) {
            r.append(Constants.ROLE_ACCOUNTANT).append("^");
        }
        Initial(username, r.toString(), fullname, active);
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getRole() {
        return role;
    }

    public void setRole(String role) {
        this.role = role;
    }

    public String getFullname() {
        return fullname;
    }

    public void setFullname(String fullname) {
        this.fullname = fullname;
    }
    
    public boolean hasRole(String role) {
        return this.role.contains("^" + role + "^");
    }

    public boolean isActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }
    
    public boolean isAdmin() {
        return hasRole(Constants.ROLE_ADMIN);
    }
    
    public boolean isAccountant() {
        return hasRole(Constants.ROLE_ACCOUNTANT);
    }
}
